/**
 * Created by Jie on 2017/1/14.
 */
var $ajax_header = {};
try{
    $ajax_header = {token: store.get('token'),uid:store.get("users")["id"]};
}catch(e){}

(function ($) {
    $.extend({
        ajaxs: function (cfg) {
            var defaults = {
                url: '',
                type: 'GET',
                data: '',
                //contentType: "application/json;charset:utf-8",
                //dataType:"json",
                async: 'true',
                cache: false,
                success: function () {
                }
            }, d = $.extend(defaults, cfg);
            var $request = $.ajax({
                url: d.url,
                type: d.type,
                data: d.data,
                async: d.async,
                //dataType: d.dataType,
                headers: $ajax_header || {},
                cache: false,
                beforeSend: function () {
                    loading();
                },
                statusCode: {
                    400: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求 -> 服务器400 参数请求错误');
                    },
                    404: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求 -> 服务器404 找不到服务');
                    },
                    405: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求 -> 服务器405 错误请求');
                    },
                    408: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->服务器408 服务器等候请求时发生超时');
                    },
                    403: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->服务器返回403 当前无权限访问');
                    },
                    500: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->服务器返回500 服务器错误');
                    },
                    503: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->服务器返回503 服务器目前无法使用');
                    },
                    200: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->成功回调200 关闭beforeSend');
                    },
                    201: function () {
                        close_loading();
                        log(d.url + ' -> ajax请求->成功回调201 关闭beforeSend');
                    }
                }
            });
            return $request;
        }
    })
})(jQuery);









